{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e368bc1e-236d-4c6c-8610-c8b4100db569",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaaaa\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = 5\n",
    "x = \"a\" * x\n",
    "print(x)\n",
    "x = 9\n",
    "x * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "09b5da8c-dee5-4404-9385-15a121a2b9a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 2, 9]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [4,2,9]\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "333f72cf-5eed-4ccf-b09f-15f08a03ed37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d3b8c25c-cc61-4cc9-96fa-f4c07c430dcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 2]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c189deff-115b-4841-95a5-fa6ab1aa391a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 2]\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "baba2f64-baa0-4ff6-9405-b0fc22c463f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "a.append(7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "02ba6740-b5df-469a-9e66-6e8b403c79d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 2, 7]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c83aea28-27d2-488d-9189-8cfd9231419a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_4 + 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "562db4ba-01c0-4415-9ebf-1483768cfbd7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[18], line 5\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m      4\u001b[0m       \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhello\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 5\u001b[0m       time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m3\u001b[39m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import time \n",
    "\n",
    "while True:\n",
    "      print('hello')\n",
    "      time.sleep(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "8ea74816-47b0-41fd-ac30-d0b726f0adc5",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = 20"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60fd699f-6851-4d6a-b129-bed7ac1a734c",
   "metadata": {},
   "source": [
    "x = 5\n",
    "print(x ** 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6275532b-b75b-4d21-af4d-f75ef497d463",
   "metadata": {},
   "source": [
    "# 这是一级标题\n",
    "\n",
    "## 这是二级标题\n",
    "\n",
    "### 这是三级标题\n",
    "\n",
    "这是一段普通的文本。你可以使用 **粗体** 或者 *斜体* 来突出显示某些文字。\n",
    "\n",
    "### 列表\n",
    "#### 无序列表\n",
    "- 项目 1\n",
    "- 项目 2\n",
    "  - 子项目 1\n",
    "  - 子项目 2\n",
    "\n",
    "#### 有序列表\n",
    "1. 第一项\n",
    "2. 第二项\n",
    "3. 第三项\n",
    "\n",
    "### 链接\n",
    "你可以通过 [这个链接](https://www.example.com) 访问示例网站。\n",
    "\n",
    "### 图片\n",
    "![示例图片](https://picsum.photos/200/300)\n",
    "\n",
    "### 代码块\n",
    "```python\n",
    "def greet(name):\n",
    "    return f\"Hello, {name}!\"\n",
    "\n",
    "print(greet(\"World\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "430be7bf-8f8f-4202-9129-04d8e5007b26",
   "metadata": {},
   "source": [
    "## 一、宇宙的浩瀚\n",
    "宇宙，是一个广袤无垠的空间，充满了无数的恒星、行星、星系和神秘的天体。它的尺度之大，超出了人类的想象。\n",
    "\n",
    "### 1.1 星系的壮丽\n",
    "星系是宇宙中由恒星、气体、尘埃和暗物质组成的巨大集合。其中，螺旋星系如银河系，拥有美丽的旋臂结构，宛如宇宙中的巨大风车。\n",
    "\n",
    "![螺旋星系](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Milky_Way_Arms.jpg/440px-Milky_Way_Arms.jpg)\n",
    "\n",
    "### 1.2 恒星的生命周期\n",
    "恒星是宇宙中的能量源泉，它们经历着诞生、成长、衰老和死亡的过程。像太阳这样的恒星，处于主序星阶段，稳定地发光发热。\n",
    "\n",
    "```python\n",
    "# 简单示意恒星质量与寿命的关系\n",
    "# 这里只是简单示例，实际关系更复杂\n",
    "def star_lifetime(mass):\n",
    "    # 假设寿命与质量的 -2.5 次方成正比\n",
    "    return 1 / (mass ** 2.5)\n",
    "\n",
    "sun_mass = 1\n",
    "print(f\"太阳质量（以太阳质量为单位）: {sun_mass}\")\n",
    "print(f\"相对寿命: {star_lifetime(sun_mass):.2f}\")\n",
    "# 简单模拟从地球到月球的距离和飞行时间\n",
    "# 假设平均速度（单位：千米/小时）\n",
    "average_speed = 3800\n",
    "# 地球到月球的平均距离（单位：千米）\n",
    "distance = 384400\n",
    "flight_time = distance / average_speed\n",
    "print(f\"从地球到月球，以平均速度 {average_speed} 千米/小时飞行，大约需要 {flight_time:.2f} 小时\")\n",
    "# 简单示意引力波频率范围\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 引力波频率范围（单位：赫兹）\n",
    "min_frequency = 1e-4\n",
    "max_frequency = 1e4\n",
    "frequencies = np.logspace(np.log10(min_frequency), np.log10(max_frequency), 100)\n",
    "\n",
    "plt.figure(figsize=(8, 6))\n",
    "plt.plot(frequencies, np.ones_like(frequencies))\n",
    "plt.xscale('log')\n",
    "plt.xlabel('频率 (Hz)')\n",
    "plt.xticks(rotation=45)\n",
    "plt.ylabel('任意强度')\n",
    "plt.title('引力波频率范围示意')\n",
    "plt.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a73da15-c83e-4f08-b827-8fa962ff3280",
   "metadata": {},
   "source": [
    "<!DOCTYPE html>\n",
    "<html lang=\"en\">\n",
    "\n",
    "<head>\n",
    "  <meta charset=\"UTF-8\">\n",
    "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n",
    "  <script src=\"https://cdn.tailwindcss.com\"></script>\n",
    "  <link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css\" rel=\"stylesheet\">\n",
    "  <title>复杂表格</title>\n",
    "  <style>\n",
    "    table {\n",
    "      border-collapse: collapse;\n",
    "      width: 100%;\n",
    "    }\n",
    "\n",
    "    th,\n",
    "    td {\n",
    "      border: 1px solid #ddd;\n",
    "      padding: 8px;\n",
    "      text-align: left;\n",
    "    }\n",
    "\n",
    "    th {\n",
    "      cursor: pointer;\n",
    "    }\n",
    "\n",
    "    .sort-icon {\n",
    "      margin-left: 5px;\n",
    "    }\n",
    "\n",
    "    .pagination {\n",
    "      display: flex;\n",
    "      justify-content: center;\n",
    "      margin-top: 20px;\n",
    "    }\n",
    "\n",
    "    .pagination button {\n",
    "      margin: 0 5px;\n",
    "      padding: 5px 10px;\n",
    "      border: 1px solid #ddd;\n",
    "      background-color: #f9fafb;\n",
    "      cursor: pointer;\n",
    "    }\n",
    "\n",
    "    .pagination button.active {\n",
    "      background-color: #007BFF;\n",
    "      color: white;\n",
    "    }\n",
    "  </style>\n",
    "</head>\n",
    "\n",
    "<body class=\"p-4\">\n",
    "  <h1 class=\"text-2xl font-bold mb-4\">复杂表格示例</h1>\n",
    "  <table id=\"data-table\">\n",
    "    <thead>\n",
    "      <tr>\n",
    "        <th onclick=\"sortTable(0)\">姓名 <i class=\"sort-icon fas fa-sort\"></i></th>\n",
    "        <th onclick=\"sortTable(1)\">年龄 <i class=\"sort-icon fas fa-sort\"></i></th>\n",
    "        <th onclick=\"sortTable(2)\">城市 <i class=\"sort-icon fas fa-sort\"></i></th>\n",
    "        <th onclick=\"sortTable(3)\">职业 <i class=\"sort-icon fas fa-sort\"></i></th>\n",
    "      </tr>\n",
    "    </thead>\n",
    "    <tbody>\n",
    "      <tr>\n",
    "        <td>张三</td>\n",
    "        <td>25</td>\n",
    "        <td>北京</td>\n",
    "        <td>程序员</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>李四</td>\n",
    "        <td>30</td>\n",
    "        <td>上海</td>\n",
    "        <td>设计师</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>王五</td>\n",
    "        <td>22</td>\n",
    "        <td>广州</td>\n",
    "        <td>教师</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>赵六</td>\n",
    "        <td>35</td>\n",
    "        <td>深圳</td>\n",
    "        <td>医生</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>孙七</td>\n",
    "        <td>28</td>\n",
    "        <td>成都</td>\n",
    "        <td>律师</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>周八</td>\n",
    "        <td>26</td>\n",
    "        <td>杭州</td>\n",
    "        <td>记者</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>吴九</td>\n",
    "        <td>32</td>\n",
    "        <td>南京</td>\n",
    "        <td>会计</td>\n",
    "      </tr>\n",
    "      <tr>\n",
    "        <td>郑十</td>\n",
    "        <td>24</td>\n",
    "        <td>武汉</td>\n",
    "        <td>工程师</td>\n",
    "      </tr>\n",
    "    </tbody>\n",
    "  </table>\n",
    "  <div class=\"pagination\" id=\"pagination\"></div>\n",
    "\n",
    "  <script>\n",
    "    const table = document.getElementById('data-table');\n",
    "    const rows = Array.from(table.tBodies[0].rows);\n",
    "    const rowsPerPage = 3;\n",
    "    let currentPage = 1;\n",
    "    let sortColumn = -1;\n",
    "    let sortDirection = 1;\n",
    "\n",
    "    function sortTable(column) {\n",
    "      if (sortColumn === column) {\n",
    "        sortDirection = -sortDirection;\n",
    "      } else {\n",
    "        sortColumn = column;\n",
    "        sortDirection = 1;\n",
    "      }\n",
    "\n",
    "      rows.sort((a, b) => {\n",
    "        const cellA = a.cells[column].textContent.trim();\n",
    "        const cellB = b.cells[column].textContent.trim();\n",
    "        return (cellA < cellB ? -1 : 1) * sortDirection;\n",
    "      });\n",
    "\n",
    "      const sortIcons = document.querySelectorAll('.sort-icon');\n",
    "      sortIcons.forEach((icon, index) => {\n",
    "        if (index === column) {\n",
    "          icon.classList.remove('fa-sort');\n",
    "          icon.classList.add(sortDirection === 1 ? 'fa-sort-up' : 'fa-sort-down');\n",
    "        } else {\n",
    "          icon.classList.remove('fa-sort-up', 'fa-sort-down');\n",
    "          icon.classList.add('fa-sort');\n",
    "        }\n",
    "      });\n",
    "\n",
    "      renderTable();\n",
    "    }\n",
    "\n",
    "    function renderTable() {\n",
    "      const startIndex = (currentPage - 1) * rowsPerPage;\n",
    "      const endIndex = startIndex + rowsPerPage;\n",
    "      const currentRows = rows.slice(startIndex, endIndex);\n",
    "\n",
    "      table.tBodies[0].innerHTML = '';\n",
    "      currentRows.forEach(row => {\n",
    "        table.tBodies[0].appendChild(row);\n",
    "      });\n",
    "\n",
    "      renderPagination();\n",
    "    }\n",
    "\n",
    "    function renderPagination() {\n",
    "      const totalPages = Math.ceil(rows.length / rowsPerPage);\n",
    "      const pagination = document.getElementById('pagination');\n",
    "      pagination.innerHTML = '';\n",
    "\n",
    "      for (let i = 1; i <= totalPages; i++) {\n",
    "        const button = document.createElement('button');\n",
    "        button.textContent = i;\n",
    "        button.classList.add('hover:bg-gray-200', 'transition-colors', 'duration-200');\n",
    "        if (i === currentPage) {\n",
    "          button.classList.add('active');\n",
    "        }\n",
    "        button.addEventListener('click', () => {\n",
    "          currentPage = i;\n",
    "          renderTable();\n",
    "        });\n",
    "        pagination.appendChild(button);\n",
    "      }\n",
    "    }\n",
    "\n",
    "    renderTable();\n",
    "  </script>\n",
    "</body>\n",
    "\n",
    "</html>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "558db1f8-e2c8-4572-a44c-676676095aa6",
   "metadata": {},
   "source": [
    "# 复杂数学公式示例\n",
    "\n",
    "## 微积分相关公式\n",
    "\n",
    "### 多元函数的泰勒展开\n",
    "对于一个 $n$ 元函数 $f(\\mathbf{x})$，其中 $\\mathbf{x}=(x_1,x_2,\\cdots,x_n)^T$，在点 $\\mathbf{a}=(a_1,a_2,\\cdots,a_n)^T$ 处的二阶泰勒展开式为：\n",
    "$$\n",
    "f(\\mathbf{x}) = f(\\mathbf{a})+\\sum_{i = 1}^{n}\\frac{\\partial f}{\\partial x_i}\\big|_{\\mathbf{x}=\\mathbf{a}}(x_i - a_i)+\\frac{1}{2}\\sum_{i = 1}^{n}\\sum_{j = 1}^{n}\\frac{\\partial^2 f}{\\partial x_i\\partial x_j}\\big|_{\\mathbf{x}=\\mathbf{a}}(x_i - a_i)(x_j - a_j)+R_2(\\mathbf{x})\n",
    "$$\n",
    "其中 $R_2(\\mathbf{x})$ 是余项。\n",
    "\n",
    "### 高斯积分\n",
    "高斯积分是概率论和统计学中非常重要的积分，其表达式为：\n",
    "$$\n",
    "\\int_{-\\infty}^{\\infty}e^{-x^2}dx=\\sqrt{\\pi}\n",
    "$$\n",
    "\n",
    "## 线性代数相关公式\n",
    "\n",
    "### 矩阵的特征值与特征向量\n",
    "对于一个 $n\\times n$ 的矩阵 $\\mathbf{A}$，如果存在一个非零向量 $\\mathbf{v}$ 和一个标量 $\\lambda$ 使得 $\\mathbf{A}\\mathbf{v}=\\lambda\\mathbf{v}$，则称 $\\lambda$ 是矩阵 $\\mathbf{A}$ 的特征值，$\\mathbf{v}$ 是对应于 $\\lambda$ 的特征向量。特征值 $\\lambda$ 满足特征方程：\n",
    "$$\n",
    "\\det(\\mathbf{A}-\\lambda\\mathbf{I}) = 0\n",
    "$$\n",
    "其中 $\\det$ 表示行列式，$\\mathbf{I}$ 是 $n\\times n$ 的单位矩阵。\n",
    "\n",
    "## 概率论相关公式\n",
    "\n",
    "### 二维正态分布的概率密度函数\n",
    "设 $(X,Y)$ 服从二维正态分布 $N(\\mu_1,\\mu_2,\\sigma_1^2,\\sigma_2^2,\\rho)$，其概率密度函数为：\n",
    "$$\n",
    "f(x,y)=\\frac{1}{2\\pi\\sigma_1\\sigma_2\\sqrt{1 - \\rho^2}}\\exp\\left\\{-\\frac{1}{2(1 - \\rho^2)}\\left[\\left(\\frac{x - \\mu_1}{\\sigma_1}\\right)^2-2\\rho\\left(\\frac{x - \\mu_1}{\\sigma_1}\\right)\\left(\\frac{y - \\mu_2}{\\sigma_2}\\right)+\\left(\\frac{y - \\mu_2}{\\sigma_2}\\right)^2\\right]\\right\\}\n",
    "$$\n",
    "其中 $\\mu_1,\\mu_2$ 分别是 $X$ 和 $Y$ 的均值，$\\sigma_1^2,\\sigma_2^2$ 分别是 $X$ 和 $Y$ 的方差，$\\rho$ 是 $X$ 和 $Y$ 的相关系数，且 $- 1 < \\rho < 1$。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "350089b1-047e-4965-a9f7-e65ea3430cb0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
